/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servicios;

import entities.AccionEstrategica;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

/**
 *
 * @author curso
 */
@Stateless
@LocalBean
public class ServicioAccionEstrategica {
    
    @PersistenceContext(name="recursividadPU")
    private EntityManager em;
    
    
    public void guardar(AccionEstrategica accionEstrategica){
        em.persist(accionEstrategica);        
    }
    
    public void modificar(AccionEstrategica accionEstrategica){        
        em.merge(accionEstrategica);
    }
    
    public void borrar(Long id){
        AccionEstrategica accion =em.find(AccionEstrategica.class, id);
        
        if(accion!=null && accion.getHijas().isEmpty())
        em.remove(accion);        
    }
    
    public List<AccionEstrategica> verTodos(){
         TypedQuery<AccionEstrategica> query = em.createQuery("SELECT a from AccionEstrategica a", AccionEstrategica.class);
        return query.getResultList();
    }
    
    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    
}
